package org.finmanager.statistics;

import org.finmanager.core.FinManager;
import org.finmanager.data.CategoryList;
import org.finmanager.data.ItemList;

import java.util.Observable;
import java.util.Observer;

/**
 * Created by Kelvin on 27/4/2014.
 */

//define the models in the statistic function
//1. bar chart
//2. pie chart
//3. statistical distribution table
//Will be used in the StatisticsController.java
public class StatisticsModel implements Observer {
	private final FinManager finManager;
	private final ItemDistributionModel itemDistributionModel;
	private final CategoryPieChartDataSet categoryPieChartDataSet;
	private final CategoryStackedBarChartDataSet categoryStackedBarChartDataSet;

	public StatisticsModel(FinManager finManager) {
		this.finManager = finManager;

		this.itemDistributionModel = new ItemDistributionModel(this);
		this.categoryPieChartDataSet = new CategoryPieChartDataSet(this);
		this.categoryStackedBarChartDataSet = new CategoryStackedBarChartDataSet(this);
	}

	public ItemDistributionModel getItemDistributionModel() {
		return itemDistributionModel;
	}

	public CategoryPieChartDataSet getCategoryPieChartDataSet() {
		return categoryPieChartDataSet;
	}

	public CategoryStackedBarChartDataSet getCategoryStackedBarChartDataSet() {
		return categoryStackedBarChartDataSet;
	}

	public ItemList getItemList() {
		return finManager.getItemList();
	}

	public CategoryList getCategoryList() {
		return finManager.getCategoryList();
	}

	@Override
	public void update(Observable o, Object arg) {
		itemDistributionModel.fireTableDataChanged();
		categoryPieChartDataSet.fireDatasetChanged();
		categoryStackedBarChartDataSet.fireDatasetChanged();
	}
}
